<?php

include '../../../configuration.php';

$old_category = $_POST['old_category'];
$category = $_POST['category'];
$faculty_ids = array();

$result = mysql_query("SELECT * FROM `categories` WHERE cat_title = '$old_category'");
$row = mysql_fetch_assoc($result);
$cat_id = $row["cat_id"];

$i = 0;
while ( $i < 3 ) {
	if($_POST["ch".$i] != null) $faculty_ids[] = $_POST["ch".$i];
	$i++;
}
$faculty_id;
for ($i = 0; $i < count($faculty_ids); $i++) {
	if ($i == (count($faculty_ids)-1)) $faculty_id .= $faculty_ids[$i];
	else $faculty_id .= $faculty_ids[$i].",";
}

mysql_query("UPDATE `categories` SET cat_title = '$category', faculty_ids = '$faculty_id' WHERE cat_id = $cat_id");

header("Location: modify_category.php");

?>